// pages/audit-status/audit-status.ts
interface AuditStatusPageData {
  statusBarHeight: number;
  applicationTime: string;
  contactPhone: string;
}

Page({
  data: {
    statusBarHeight: 0,
    applicationTime: '',
    contactPhone: ''
  } as AuditStatusPageData,

  onLoad() {
    const systemInfo = wx.getSystemInfoSync();
    this.setData({
      statusBarHeight: systemInfo.statusBarHeight || 0
    });

    // 获取商家信息
    const merchantInfo = wx.getStorageSync('merchantUserInfo');
    if (merchantInfo) {
      this.setData({
        contactPhone: merchantInfo.contactPhone || '',
        applicationTime: this.formatDate(new Date())
      });
    }
  },

  // 格式化日期
  formatDate(date: Date): string {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hour = String(date.getHours()).padStart(2, '0');
    const minute = String(date.getMinutes()).padStart(2, '0');
    return `${year}-${month}-${day} ${hour}:${minute}`;
  },

  // 联系客服
  contactService() {
    wx.makePhoneCall({
      phoneNumber: '400-888-8888' // 替换为实际客服电话
    });
  },

  // 返回登录
  backToLogin() {
    // 清除token和用户信息，避免自动登录
    wx.removeStorageSync('merchantToken');
    wx.removeStorageSync('merchantUserInfo');
    
    wx.redirectTo({
      url: '/pages/auth/auth'
    });
  }
});
